package com.lq.filter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 编码过滤器
 */
@WebFilter("/*")
public class CharSetFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        //过滤器做一些统一操纵，这里设置浏览器需要的编码为utf-8,以放置乱码
        response.setContentType("text/html;charset=utf-8");
        //写了过滤器，一定一定要执行下面的放行操纵，不然页面一篇白板
        chain.doFilter(request, response);
    }
}
